home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
admin
/
linuxcon.000
/
linuxcon
/
linuxconf-1.6
/
userconf
/
privi.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-20
|
3KB
|
110 lines
#include <stdio.h>
#include <stdlib.h>
#include "../misc/misc.h"
#include "../dialog/dialog.h"
#include "userconf.h"
#include "userconf.m"
/* #Specification: privileges / intro
The privilege system of Linuxconf let you give special power to
end user. Linuxconf manage quite a few feature of a system and
each component of linuxconf can associate itself with a special
privilege. When trying to perform something special, the component
ask permission to the perm_access() function passing it the
PRIVILEGE object which fit its security scheme.
When perm_access() is called, either the root password or the user
password must be supplied. If the user has this privilege, then
operation can continue.
The privilege feature is unique to linuxconf. A privileged user
has no special UID or GID. Out of linuxconf, it is a plain normal
users.
This concept is expect to grow in the following directions
#
-Assigning privilege to group.
-Allowing some flexibility to user authentication. For exemple
one user won't have to provide his password if he is accessing
linuxconf in such or such context. This would help make linux
much more user friendly.
-Assigning password to privilege
#
PRIVILEGE objects are always static and link together, so we know
at run time all the privilege that exist in the application. This
is used to dunamically create the USER configuration dialog.
*/
static PRIVILEGE *first;
PUBLIC PRIVILEGE::PRIVILEGE(const char *_id)
{
id.setfrom (_id);
next = first;
first = this;
}
/* #Specification: privilege / default type
A standard privilege is associate
*/
class PRIVILEGE_DATA_SIMPLE: public PRIVILEGE_DATA{
/*~PROTOBEG~ PRIVILEGE_DATA_SIMPLE */
public:
PRIVILEGE_DATA_SIMPLE (const char *line);
PRIVILEGE_DATA_SIMPLE (void);
void format_ascii (char *line);
void setdialog (DIALOG&dia);
int validate (void);
/*~PROTOEND~ PRIVILEGE_DATA_SIMPLE */
};
PUBLIC PRIVILEGE_DATA_SIMPLE::PRIVILEGE_DATA_SIMPLE(const char *line)
{
int x,y;
sscanf (line,"%d %d",&x,&y);
active = (char)x;
authenticate = (char)y;
}
PUBLIC PRIVILEGE_DATA_SIMPLE::PRIVILEGE_DATA_SIMPLE()
{
active = 0;
authenticate = 1;
}
/*
format in ascii so the information may be stored in /etc/conf.linuxconf
*/
PUBLIC void PRIVILEGE_DATA_SIMPLE::format_ascii(char *line)
{
sprintf (line,"%d %d",active,authenticate);
}
/*
Return 0 if the privilege is not granted to this users.
Return 1 if the privilege is granted, but user must authenticate
Return 2 if the privilege is granted, no question ask!
*/
PUBLIC int PRIVILEGE_DATA_SIMPLE::validate()
{
int ret = 0;
if (active){
ret = 1;
if (!authenticate) ret = 2;
}
return ret;
}
PUBLIC void PRIVILEGE_DATA_SIMPLE::setdialog(DIALOG &dia)
{
dia.newf_chk (MSG_U(F_PRIVENABLE,"Grant"),active,"");
dia.newf_chk ("",authenticate,MSG_U(F_AUTHENTICATE,"Must authenticate"));
}
/*
A PRIVILEGE_DATA object to edit and control that kind
of privilege. line contain raw info used to initialise the new object.
*/
PUBLIC VIRTUAL PRIVILEGE_DATA *PRIVILEGE::getdata (const char *line)
{
return new PRIVILEGE_DATA_SIMPLE (line);
}